package com.tueye.base.util;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.ResultTransformer;
import org.springframework.dao.DataAccessException;

/**
 * Hibernate 的基层封装
 * 
 * @author hanxiaowei
 * @see 2008-12-09
 * 
 */

public interface IBaseHbnDao {

	/**
	 * 
	 * @param entityName
	 * @param entity
	 * @throws DataAccessException
	 */
	public void update(final String entityName, final Object entity)
			throws DataAccessException;

	/**
	 * 
	 * @param entity
	 * @throws DataAccessException
	 */
	public void delete(final Object entity) throws DataAccessException;

	/**
	 * 
	 * @param entities
	 * @throws DataAccessException
	 */
	public void deleteAll(final Collection entities) throws DataAccessException;

	/**
	 * 
	 * @param entityName
	 * @param entity
	 * @throws DataAccessException
	 */
	public void saveOrUpdate(final String entityName, final Object entity)
			throws DataAccessException;

	public void saveOrUpdate(final Object entity) throws DataAccessException;
	public void merge(final Object entity) throws DataAccessException;
	/**
	 * 
	 * @param entity
	 * @return
	 * @throws DataAccessException
	 */
	public Object save(final Object entity) throws DataAccessException;

	/**
	 * 
	 * @param entities
	 * @throws DataAccessException
	 */
	public void saveOrUpdateAll(final Collection entities)
			throws DataAccessException;

	/**
	 * 
	 * @param entityClass
	 * @param id
	 * @return
	 * @throws DataAccessException
	 */
	public Object findById(final Class entityClass, final Serializable id)
			throws DataAccessException;

	/**
	 * 
	 * @param entityClass
	 * @param id
	 * @return
	 * @throws DataAccessException
	 */
	public Object findByIdFlush(final Class entityClass, final Serializable id)
			throws DataAccessException;

	/**
	 * 
	 * @param queryName
	 * @param values
	 * @return
	 * @throws DataAccessException
	 */
	public List findByNamedQuery(final String queryName, final Object[] values)
			throws DataAccessException;

	public List findByHqlQuery(final String queryName, final Object[] values)
			throws DataAccessException;

	/**
	 * 通过HQL查询相关表
	 * 
	 * @param hql
	 * @return
	 * @throws DataAccessException
	 */
	@SuppressWarnings("unchecked")
	public List queryList(final String hql) throws DataAccessException;

	@SuppressWarnings("unchecked")
	public List find(final String hql, final Serializable id)
			throws DataAccessException;

	@SuppressWarnings("unchecked")
	public List queryBySqlList(final String sql) throws DataAccessException;

	/**
	 * 
	 * @param flush
	 */
	public void bussFlush(boolean flush);

	/**
	 * 
	 * @param hql
	 * @throws DataAccessException
	 */
	public void delete(final String hql) throws DataAccessException;

	/**
	 * 
	 * @param entityClass
	 * @param id
	 * @return
	 */
	public Object loadById(final Class entityClass, final Serializable id);

	/**
	 * 取得当前SESSION
	 * 
	 * @return
	 * @throws DataAccessException
	 */
	public Session getCurrSession() throws DataAccessException;

	/**
	 * 
	 * @param hql
	 * @param values
	 * @return
	 */
	public Query createQuery(final String hql, final Object... values);

	/**
	 * 
	 * @param hql
	 * @param pageNo
	 * @param pageSize
	 * @param values
	 * @return
	 */
	public Page pagedQueryByHQL(final String hql, final int pageNo,
			final int pageSize, final Object... values);

	/**
	 * 
	 * @param hql
	 * @param pageNo
	 * @param pageSize
	 * @param resultTransformer
	 * @param values
	 * @return
	 */
	public Page pagedQueryByHQL(final String hql, final int pageNo,
			final int pageSize, final ResultTransformer resultTransformer,
			final Object... values);

}
